package com.zxk.version3.consumer;


import com.zxk.version3.api.BlogService;
import com.zxk.version3.api.UserService;
import com.zxk.version3.core.Blog;
import com.zxk.version3.core.User;

/**
 * @author 朱小康
 */
public class RpcClient {
    public static void main(String[] args) {
        //建立socket链接
        try {
            ClientProxy clientProxy = new ClientProxy("127.0.0.1",8083);
            UserService userService = clientProxy.getProxy(UserService.class);


            User userByUserId = userService.getUserByUserId(10);
            System.out.println("从服务端得到的user为：" + userByUserId);
            // 服务的方法2
            User user = User.builder().userName("张三").id(100).sex(true).build();
            Integer integer = userService.insertUser(user);
            System.out.println("向服务端插入数据："+integer);

            // 客户中添加新的测试用例
            BlogService blogService = clientProxy.getProxy(BlogService.class);
            Blog blogById = blogService.getBlogById(10000);
            System.out.println("从服务端得到的blog为：" + blogById);


        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("出现异常");
        }
    }
}
